package com.amado.course30Util;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * list 列表 有序的 collection（也称为序列）。
 * 
 * @author Administrator
 *
 */
public class S05ListIteratorCount {
	private static List list = new ArrayList();

	public static void init() {
//		list.clear();
		System.out.println("come static");
		list.add("1");
		list.add("2");
		list.add("3");
		list.add("4");
	}

	public static void main(String[] args) {
		init();
		String deleteValue = "2";
		delete(deleteValue);
		list.clear();
		init();
		deleteForEach(deleteValue);
		init();
		
		deleteForIntI(deleteValue);

	}

	public static void delete(String deleteValue) {
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			Object value = iterator.next();
			if (value.equals(deleteValue)) {
				iterator.remove();
			}
		}
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			System.out.println(iterator.next());
		}
	}

	public static void deleteForEach(String deleteValue) {
		/**
		 * 这种跌代过程是不能删除数据的
		 */
		for (Object obj : list) {
			if (obj.equals(deleteValue)) {
				list.remove(obj);
			}
		}
		for (Object obj : list) {
			System.out.print(obj);
		}
	}

	public static void deleteForIntI(String deleteValue) {
		System.out.println("-000000000000");
		for (int i = 0; i < list.size(); i++) {
			if (deleteValue.equals(list.get(i))) {
				list.remove(i);
			}
		}
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
	}
}
